import { createRouter, createWebHashHistory } from 'vue-router';
export const rootPath = window.__MICRO_APP_BASE_ROUTE__ || '/';
export const rootPathJoin = (path = '') => {
  if (path === '') {
    return rootPath;
  }
  if (rootPath === '/') {
    return path.startsWith('/') ? path : rootPath + path;
  }
  return path.startsWith('/') ? rootPath + path : rootPath + '/' + path;
};
const routes = [
  // {
  //   path: '/',
  //   name: '首页',
  //   component: () => import('@/views/home/index.vue')
  // },
  {
    path: '/index',
    component: () => import('@/views/index/index.vue')
    // redirect: '/index'
  },
  {
    path: window.__MICRO_APP_BASE_ROUTE__ || '/',
    name: '首页',
    component: () => import('@/views/index/index.vue'),
    children: [
      {
        name: 'create',
        path: '/index/create',
        component: () => import('@/views/create/index.vue') // 公文首发
      },
      { path: '/index/handle', component: () => import('@/views/handle/index.vue') }, // 公文办理
      { path: '/index/exchange', component: () => import('@/views/exchange/index.vue') },
      { path: '/index/library', component: () => import('@/views/library/index.vue') }
    ]
  },
  {
    path: '/library/download',
    name: '批量下载',
    component: () => import('@/views/library/download/index.vue')
  },
  {
    path: '/library/print',
    name: '批量下载',
    component: () => import('@/views/library/download/indexPrint.vue')
  },
  {
    path: '/library/onlyDownload',
    name: '单独下载url',
    component: () => import('@/views/library/download/download.vue')
  },
  {
    path: '/library/indexPrintZhengwen',
    name: '打印正文',
    component: () => import('@/views/library/download/indexPrintZhengwen.vue')
  },
  {
    path: '/formPage',
    name: 'formPage',
    component: () => import('@/views/formPage/index.vue')
  },
  {
    path: '/examinePage',
    name: 'examinePage',
    component: () => import('@/views/examinePage/index.vue')
  }
];

// const router = createRouter({
//   history: createWebHashHistory(),
//   routes
// });

// export default router;
export function setupRouter() {
  const base = window.__MICRO_APP_BROWER_VIEW__ ? window.__MICRO_APP_BASE_ROUTE__ : './';
  const history = createWebHashHistory(base);
  const router = createRouter({
    history: history,
    routes
  });

  return {
    history,
    router
  };
}
